package com.star.mapper;

import com.github.pagehelper.Page;
import com.star.annotation.AutoFill;
import com.star.dto.SetmealPageQueryDTO;
import com.star.entity.Setmeal;
import com.star.enumeration.OperationType;
import com.star.vo.DishItemVO;
import com.star.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 新增套餐基本数据
     * @param setmeal
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Setmeal setmeal);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal getById(Long id);

    /**
     * 更新套餐表基本数据
     * @param setmeal
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 根据套餐id集合批量删除套餐数据
     * @param ids
     */
    void deleteBySetmealIds(List<Long> ids);

    /**
     * 动态条件查询套餐起售/停售数量
     * @param setmeal
     * @return
     */
    Integer countByStatus(Setmeal setmeal);

    /**
     * 动态条件查询套餐列表
     * @param setmeal
     * @return
     */
    List<Setmeal> getBySetmeal(Setmeal setmeal);

    /**
     * 根据套餐id查询包含的菜品
     * @param setmealId
     * @return
     */
    @Select("select sd.*, d.description, d.image from setmeal_dish as sd left join dish as d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<SetmealVO> getDishItemById(Long setmealId);
}
